home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-06 | 7.3 KB | 294 lines | [TEXT/CWIE] |
- //========================================================================
- // Application: QTICSampleApp
- //
- // Description: This application demonstrates the integration of
- // QuickTime™ IC functionality.
- //
- // Author: Mike Bitz
- // Developer Technical Support
- // Apple Computer, Inc.
- //
- // History: 25-Apr-97 original development (mwb)
- //
- // Copyright © 1997 Apple Computer, Inc., All Rights Reserved
- //
- // You may incorporate this sample code into your applications without
- // restriction, though the sample code has been provided "AS IS" and the
- // responsibility for its operation is 100% yours. However, what you are
- // not permitted to do is to redistribute the source as "DSC Sample Code"
- // after having made changes. If you're going to re-distribute the source,
- // we require that you make it clear in the source that the code was
- // descended from Apple Sample Code, but that you've made changes.
- //========================================================================
-
-
- #include "prototypes.h"
- #include "application.h"
- #include <QTIC.h>
-
- extern Boolean gDone;
- extern QTICControls gCameraControls;
- extern Component gPanelComponents[10];
- extern short gNumPanels, gNumPrefPanels;
-
-
- //================= SetupMenus =================
- void SetupMenus (void)
- {
- Handle hMenuBar = nil;
- MenuHandle hAppleMenu = nil, hFileMenu = nil;
- short numCameras = 0;
-
- // Use our MBAR resource
- hMenuBar = GetNewMBar (kBaseResID);
- if (hMenuBar == nil)
- {
- DebugStr ("\pMenu bar problems...");
- ExitToShell ();
- }
- SetMenuBar (hMenuBar);
-
- // Set up the Apple menu
- hAppleMenu = GetMHandle (menuApple);
- AddResMenu (hAppleMenu, 'DRVR');
- DrawMenuBar ();
-
- // Disable the Close Window menu item since no windows are visible.
- UpdateCloseWindowItem ();
-
- // If only one camera component is installed, disable the "Select Camera" menu item.
- hFileMenu = GetMHandle (menuFile);
- numCameras = NumberOfInstalledCameras ();
- if (numCameras == 1)
- {
- DisableItem (hFileMenu, itemSelectCamera);
- }
- else
- {
- // More than one component is installed, so disable the "show main panel" item.
- DisableItem (hFileMenu, itemDisplayMainPanel);
- }
-
- // Update the menu list of available panels
- UpdatePanelListMenu ();
- }
-
- //================= HandleMenuChoice =================
- void HandleMenuChoice (long menuChoice)
- {
- short menu, item;
-
- if (menuChoice != 0)
- {
- menu = HiWord (menuChoice);
- item = LoWord (menuChoice);
-
- switch (menu)
- {
- // Dispatch to the appropriate menu-handling function.
- case menuApple:
- HandleAppleMenuChoice (item);
- break;
-
- case menuFile:
- HandleFileMenuChoice (item);
- break;
-
- case menuEdit:
- HandleEditMenuChoice (item);
- break;
-
- case menuPanels:
- HandlePanelListChoice (item);
- break;
-
- default:
- HandlePanelSpecificChoice( menu, item );
- break;
- }
- HiliteMenu (0);
- }
- }
-
- //================= HandleAppleMenuChoice =================
- void HandleAppleMenuChoice (short item)
- {
- OSErr err = noErr;
- MenuHandle hAppleMenu = nil;
- Str255 accessoryName;
- short accessoryNumber;
-
- switch (item)
- {
- case itemAboutQTIC:
- // Display the QTIC about box
- err = QTICCAboutBox (gCameraControls);
- if (err != noErr)
- QTICCReportError (gCameraControls, "\pQTICCAboutBox failed", err);
- break;
-
- case itemAboutSampleApp:
- // Display application-specific about box
- HandleMyAboutBox ();
- break;
-
- default:
- // Handle selection of Apple menu items
- hAppleMenu = GetMHandle (menuApple);
- GetItem (hAppleMenu, item, accessoryName);
- accessoryNumber = OpenDeskAcc (accessoryName);
- break;
- }
- }
-
- //================= HandleFileMenuChoice =================
- void HandleFileMenuChoice (short item)
- {
- OSErr err = noErr;
- MenuHandle hFileMenu = nil;
-
- switch (item)
- {
- case itemSelectCamera:
- // Select a camera if there are multiple 'cmra' components installed.
- err = QTICCSelectCamera (gCameraControls);
- if (err == noErr)
- {
- // Place camera panel item in our menu
- UpdatePanelListMenu ();
-
- // User selected a default camera, so enable the "show main panel" item.
- hFileMenu = GetMHandle (menuFile);
- EnableItem (hFileMenu, itemDisplayMainPanel);
- }
- break;
-
- case itemDisplayMainPanel:
- // Display the main panel for the selected camera component.
- err = (OpenMainPanel ());
- if (err != noErr)
- {
- QTICCReportError (gCameraControls, "\pOpenMainPanel failed", err);
- }
- break;
-
- case itemCloseWindow:
- // Close the window properly (deal with both QTIC and normal windows),
- // then be sure to update the panel window in case we closed a panel.
- err = CloseAppWindow ();
- UpdatePanelSpecificMenu ();
-
- break;
-
- case itemQuit:
- gDone = true;
- break;
- }
- }
-
- //================= HandleEditMenuChoice =================
- void HandleEditMenuChoice (short item)
- {
- switch (item)
- {
- // Edit menu items not yet implemented...
- case itemUndo:
- break;
-
- case itemCut:
- break;
-
- case itemCopy:
- break;
-
- case itemPaste:
- break;
-
- case itemClear:
- break;
- }
- }
-
- //================= HandlePanelListChoice =================
- void HandlePanelListChoice (short item)
- {
- OSErr err = noErr;
- MenuHandle hPanelListMenu = nil, hFileMenu = nil;
-
- if (gCameraControls != nil)
- {
- hPanelListMenu = GetMHandle (menuPanels);
- hFileMenu = GetMHandle (menuFile);
-
- if (item <= gNumPanels)
- {
- // selected item before the divider (template panel, etc.)
- err = QTICCDoAction (gCameraControls, kQTICActionIsPanelOpenByComponent,
- (void *)gPanelComponents[item - 1], nil, nil, nil);
- if (err == 0)
- {
- // Panel is already open. Close it.
- err = QTICCDoAction (gCameraControls, kQTICActionClosePanelByComponent,
- (void *)gPanelComponents[item - 1], nil, nil, nil);
- QTICCIdle (gCameraControls);
- }
- else if (err == 1)
- {
- // Panel is currently closed. Open it.
- err = QTICCDoAction (gCameraControls, kQTICActionOpenPanelByComponent,
- (void *)gPanelComponents[item - 1], nil, nil, nil);
- }
- }
- else
- {
- // selected item after the divider (preference panel)
- err = QTICCDoAction (gCameraControls, kQTICActionOpenPanelByComponent,
- (void *)gPanelComponents[item - 1], nil, nil, nil);
- }
-
- UpdateCloseWindowItem ();
- UpdatePanelSpecificMenu ();
- }
- }
-
- //================= HandlePanelSpecificChoice =================
- void HandlePanelSpecificChoice (short menuID, short item)
- {
- OSErr err = noErr;
- MenuHandle hTempMenu = nil;
- WindowPtr frontWindow = nil;
-
- frontWindow = FrontWindow ();
-
- hTempMenu = GetMHandle(menuID);
- if (hTempMenu != nil)
- {
- err = QTICCDoCustomMenu (gCameraControls, frontWindow, hTempMenu, item);
- if (err != noErr)
- {
- // Use the QTIC facilities to report the error
- QTICCReportError (gCameraControls, "\pQTICCDoCustomMenu failed", err);
- }
- }
- }
-
- //================= UpdateCloseWindowItem =================
- void UpdateCloseWindowItem (void)
- {
- WindowPtr frontWindow = nil;
- MenuHandle hFileMenu = nil;
-
- frontWindow = FrontWindow ();
- hFileMenu = GetMHandle (menuFile);
-
- if (frontWindow == nil)
- {
- // Disable the Close Window menu item since no more windows are visible.
- DisableItem (hFileMenu, itemCloseWindow);
- }
- else
- {
- // Enable the Close Window menu item since at least one window is visible.
- EnableItem (hFileMenu, itemCloseWindow);
- }
- }